VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Begin VB.Form Form1 
   Caption         =   "Common Dialog Example"
   ClientHeight    =   5895
   ClientLeft      =   60
   ClientTop       =   360
   ClientWidth     =   11880
   LinkTopic       =   "Form1"
   ScaleHeight     =   5895
   ScaleWidth      =   11880
   StartUpPosition =   2  'CenterScreen
   Begin RichTextLib.RichTextBox RichTextBox1 
      Height          =   5055
      Left            =   4440
      TabIndex        =   6
      Top             =   360
      Width           =   6735
      _ExtentX        =   11880
      _ExtentY        =   8916
      _Version        =   393217
      Enabled         =   -1  'True
      TextRTF         =   $"Form1.frx":0000
   End
   Begin VB.CommandButton Command6 
      Caption         =   "ShowHelp"
      Height          =   735
      Left            =   960
      TabIndex        =   5
      Top             =   4680
      Width           =   2655
   End
   Begin VB.CommandButton Command5 
      Caption         =   "ShowPrinter"
      Height          =   735
      Left            =   960
      TabIndex        =   4
      Top             =   3840
      Width           =   2655
   End
   Begin VB.CommandButton Command4 
      Caption         =   "ShowFont"
      Height          =   735
      Left            =   960
      TabIndex        =   3
      Top             =   3000
      Width           =   2655
   End
   Begin VB.CommandButton Command3 
      Caption         =   "ShowColor"
      Height          =   735
      Left            =   960
      TabIndex        =   2
      Top             =   2160
      Width           =   2655
   End
   Begin VB.CommandButton Command2 
      Caption         =   "ShowSave"
      Height          =   735
      Left            =   960
      TabIndex        =   1
      Top             =   1200
      Width           =   2655
   End
   Begin VB.CommandButton Command1 
      Caption         =   "ShowOpen"
      Height          =   735
      Left            =   960
      TabIndex        =   0
      Top             =   360
      Width           =   2655
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   120
      Top             =   4440
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'~~> ShowOpen Example
Private Sub Command1_Click()
    On Error GoTo cancel_error
    
    With CommonDialog1
        '~~> Set the Title of the Dialog Box
        .DialogTitle = "Open"
        '~~> Set the Initial directory
        .InitDir = "C:\"
        '~~> Set the Filter for the files that you want to open
        .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        '~~> Displays the Open Dialog Box
        .ShowOpen
    End With
    
    '~~> Load the Rich Text Box with the text file
    RichTextBox1.LoadFile CommonDialog1.FileName
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub

'~~> ShowSave Example
Private Sub Command2_Click()
    On Error GoTo cancel_error
    
    With CommonDialog1
        '~~> Set the Title of the Dialog Box
        .DialogTitle = "Open"
        '~~> Set the Initial directory
        .InitDir = "C:\"
        '~~> Set the Filter for the files that you want to save as
        .Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
        '~~> Displays the Save Dialog Box
        .ShowSave
    End With
    
    '~~> Save the Rich Text Box contents as a text file
    RichTextBox1.SaveFile CommonDialog1.FileName
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub

'~~> ShowColor Example
Private Sub Command3_Click()
    On Error GoTo cancel_error
    
    With CommonDialog1
          .DialogTitle = "Color"
          '~~> Show the Color Dialog box
          .ShowColor
     End With
     
     '~~> Set the back color of the Dialogbox
     RichTextBox1.BackColor = CommonDialog1.Color
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub

'~~> ShowFont Example
Private Sub Command4_Click()
    On Error GoTo cancel_error
    
    With CommonDialog1
        .DialogTitle = "Font"
        
        '~~> Various flags that you can use
        ' cdlCFBoth         ~~> Display Screen's and Printer's fonts
        ' cdlCFEffects      ~~> For Underline, FontStrikethru, Color
        ' cdlCFTTOnly       ~~> Display True Type fonts
        ' cdlCFScreenFonts  ~~> Displays Screen fonts
        ' cdlCFPrinterFonts ~~> Displays Printer fonts
        
        .Flags = cdlCFBoth Or cdlCFEffects
        
        '~~> Show the Font Dialog box
        .ShowFont
    End With
    
    '~~> Select the entire text in the Rich Text Box
    '~~> Comment the below two lines if you want to
    '~~> Manually select words in the Rich Text Box
    RichTextBox1.SelStart = 0
    RichTextBox1.SelLength = Len(RichTextBox1)
    
    '~~> Change Font
    RichTextBox1.SelFontName = CommonDialog1.FontName
    '~~> Change Font Size
    RichTextBox1.SelFontSize = CommonDialog1.FontSize
    '~~> Bold Font
    RichTextBox1.SelBold = CommonDialog1.FontBold
    '~~> Italicize Font if ticked
    RichTextBox1.SelItalic = CommonDialog1.FontItalic
    '~~> Underline if ticked
    RichTextBox1.SelUnderline = CommonDialog1.FontUnderline
    
    '~~> Strike through Font if ticked
    RichTextBox1.SelStrikeThru = CommonDialog1.FontStrikethru
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub

'~~> ShowPrinter Example
Private Sub Command5_Click()
    On Error GoTo cancel_error
    
    '~~> Show the printer dialog box
    CommonDialog1.ShowPrinter
    
    '~~> Print the text in the Rich Text Box
    Printer.Print RichTextBox1.Text
    Printer.EndDoc
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub

'~~> ShowHelp Example
Private Sub Command6_Click()
    On Error GoTo cancel_error
    
    '~~> Set the help file
    CommonDialog1.HelpFile = "MyHelp.hlp"
    CommonDialog1.HelpCommand = cdlHelpContents
    '~~> Show the Help File
    CommonDialog1.ShowHelp
Exit Sub

cancel_error:
     If Err.Number <> vbCancel Then
          MsgBox Err.Description
     End If
End Sub
